package com.heima.article.lisener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.common.enums.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author shiminghui
 * @date 2024/12/4 21:15
 * @description: TODO
 */
@Component
@Slf4j
public class ArticleIsDownListener {
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void downOrUp(String message) {
        if (StringUtils.isEmpty(message)) {
            return;
        }
        Map<String, Object> map = JSON.parseObject(message, Map.class);
        if (map == null) {
            log.error("消息解析失败");
            return;
        }

        // 调用方法更新文章状态
        apArticleConfigService.updateByMap(map);

    }
}
